<template>
	<view class="mainpadding2">
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期一</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(1)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_1" :key="item.id" @click="edititem(item)">
				<text
					class="margin_right2">{{item.cginfo.name || ""}}/{{item.jlinfo.name}}:{{item.start_time}}-{{item.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期二</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(2)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_2" :key="item.id" @click="edititem(item)">
				<text
					class="margin_right2">{{item.cginfo.name || ""}}/{{item.jlinfo.name}}:{{item.start_time}}-{{item.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期三</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(3)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_3" :key="item.id" @click="edititem(item)">
				<text
					class="margin_right2">{{item.cginfo.name || ""}}/{{item.jlinfo.name}}:{{item.start_time}}-{{item.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期四</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(4)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_4" :key="item.id" @click="edititem(item)">
				<text
					class="margin_right2">{{item.cginfo.name || ""}}/{{item.jlinfo.name}}:{{item.start_time}}-{{item.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期五</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(5)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_5" :key="item.id" @click="edititem(item)">
				<text
					class="margin_right2">{{item.cginfo.name || ""}}/{{item.jlinfo.name}}:{{item.start_time}}-{{item.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期六</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(6)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_6" :key="item.id" @click="edititem(item)">
				<text
					class="margin_right2">{{item.cginfo.name || ""}}/{{item.jlinfo.name}}:{{item.start_time}}-{{item.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期日</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(0)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_0" :key="item.id" @click="edititem(item)">
				<text
					class="margin_right2">{{item.cginfo.name || ""}}/{{item.jlinfo.name}}:{{item.start_time}}-{{item.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<u-modal :show="show" title="课程表管理" confirmText="确认" @confirm="chongzhi" cancelText="取消"
			@cancel="chongzhicancel" showCancelButton>
			<view class="slot-content" style="width: 600rpx;">
				<view class="flexbetween margin_top" @click="timetype=1;messageTime.timeShow=true;">
					<view class="main_size bold hei_text" style="min-width: 160rpx;">开始时间：</view>
					<view class="flexright">
						<input type="text" class="textright" placeholder="请选择" disabled v-model="start_time">
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
				</view>
				<view class="flexbetween margin_top" @click="timetype=2;messageTime.timeShow=true;">
					<view class="main_size bold hei_text" style="min-width: 160rpx;">结束时间：</view>
					<view class="flexright">
						<input type="text" class="textright" placeholder="请选择" disabled v-model="end_time">
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
				</view>
				<view class="flexbetween margin_top" v-if="type==4" @click="jlShow=true;">
					<view class="main_size bold hei_text" style="min-width: 160rpx;">教练：</view>
					<view class="flexright">
						<input type="text" class="textright" placeholder="请选择" disabled v-model="jl_user_zbfapply_name">
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
				</view>
				<view class="flexbetween margin_top" v-if="type==5" @click="cgShow=true">
					<view class="main_size bold hei_text" style="min-width: 160rpx;">场馆：</view>
					<view class="flexright">
						<input type="text" class="textright" placeholder="请选择" disabled
							v-model="glcg_user_zbfapply_name">
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
				</view>
				<view class="bigbtn margin_top6" v-if="listid" @click="delitem">删除</view>
			</view>
		</u-modal>
		<u-picker :show="cgShow" :columns="cgList" title="选择场馆" @cancel="cgShow=false" @confirm="cgconfirm"
			keyName="name"></u-picker>
		<u-picker :show="jlShow" :columns="jlList" title="选择教练" @cancel="jlShow=false" @confirm="jlconfirm"
			keyName="name"></u-picker>
		<timePicker :messageTime="messageTime" @timeConfirm="timeConfirm"></timePicker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				dataAll: {},
				week_num: 0, //星期:0=星期日,1=星期一,2=星期二,3=星期三,4=星期四,5=星期五,6=星期六
				kc_id: "",
				glcg_user_zbfapply_id: "",
				glcg_user_zbfapply_name: "",
				start_time: "",
				end_time: "",
				jl_user_zbfapply_id: "",
				jl_user_zbfapply_name: "",
				show: false,
				listid: "",
				type: 1, //身份:1=主办方,2=俱乐部,3=团队，4场馆，5教练
				cgShow: false,
				cgList: [],
				jlShow: false,
				jlList: [],
				messageTime: {
					timeShow: false,
					title: "选择时间",
					mode: "time", //date日期，datetime年月日时分秒，time时间
					minDate: "" //最小时间
				},
				timetype: 1,
				user_zbfapply_listid:""
			}
		},
		onLoad(options) {
			this.user_zbfapply_listid=options.user_zbfapply_listid
			this.type=options.type
			this.kc_id = options.id
			this.getDetail()
			this.getjl()
			this.getcg()
		},
		methods: {
			edititem(item) {
				this.week_num = item.week_num
				this.glcg_user_zbfapply_id = item.glcg_user_zbfapply_id
				this.glcg_user_zbfapply_name = item.cginfo.name
				this.start_time = item.start_time
				this.end_time = item.end_time
				this.jl_user_zbfapply_id = item.jl_user_zbfapply_id
				this.jl_user_zbfapply_name = item.jlinfo.name
				this.listid = item.id
				this.show = true
			},
			timeConfirm(e) {
				console.log(e,"999");
				if (this.timetype == 1) {
					this.start_time = e
				} else {
					this.end_time = e
				}
			},
			getcg() { //场馆
				httpRequest.request('/api/kccl/cgUserzbfapplyIndex', 'GET', {
					user_zbfapply_id:this.user_zbfapply_listid
				}, false, false, true).then(res => {
					this.cgList.push(res.data)
				})
			},
			delitem() {
				httpRequest.request('/api/kccl/deleteKcKcb', 'GET', {
					id: this.listid,
					user_zbfapply_id:this.user_zbfapply_listid
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.chongzhicancel()
						this.getDetail()
					}
				})
			},
			cgconfirm(e) {
				this.glcg_user_zbfapply_id = e.value[0].id
				this.glcg_user_zbfapply_name = e.value[0].name
				this.cgShow = false
			},
			getjl() { //教练
				httpRequest.request('/api/user/cgJlIndex', 'GET', {
					page: 1,
					limit: 100000,
					user_zbfapply_id:this.user_zbfapply_listid
				}, false, false, true).then(res => {
					res.data.data.forEach(item => {
						this.$set(item, "name", item.zbfapply.name)
					})
					this.jlList.push(res.data.data)
				})
			},

			jlconfirm(e) {
				this.jl_user_zbfapply_id = e.value[0].jl_user_zbfapply_id
				this.jl_user_zbfapply_name = e.value[0].name
				console.log(this.jl_user_zbfapply_name);
				this.jlShow = false
			},
			chongzhicancel() {
				this.start_time = ""
				this.end_time = ""
				this.glcg_user_zbfapply_id = ""
				this.glcg_user_zbfapply_name = ""
				this.jl_user_zbfapply_id = ""
				this.jl_user_zbfapply_name = ""
				this.listid = ""
				this.show = false
				this.messageTime.timeShow = false
			},
			chongzhi() {
				if (this.start_time == "") {
					httpRequest.toast("请选择开始时间")
					return false
				}
				if (this.end_time == "") {
					httpRequest.toast("请选择结束时间")
					return false
				}
				if (this.jl_user_zbfapply_name == "" && this.type==4) {
					httpRequest.toast("请选择教练")
					return false
				}
				if (this.glcg_user_zbfapply_name == "" && this.type==5) {
					httpRequest.toast("请选择场馆")
					return false
				}
				let url = "/api/kccl/addKcKcb"
				let data = {
					kc_id: this.kc_id,
					week_num: this.week_num,
					glcg_user_zbfapply_id: this.glcg_user_zbfapply_id,
					start_time: this.start_time,
					end_time: this.end_time,
					jl_user_zbfapply_id: this.jl_user_zbfapply_id,
					user_zbfapply_id:this.user_zbfapply_listid
				}
				if (this.type == 4) delete data.glcg_user_zbfapply_id
				if (this.type == 5) delete data.jl_user_zbfapply_id
				if (this.listid) {
					this.$set(data, "id", this.listid)
					url = "/api/kccl/editKcKcb"
				}
				httpRequest.request(url, 'GET', data).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.chongzhicancel()
						this.getDetail()
					}
				})
			},
			addkc(val) {
				this.week_num = val
				this.show = true
			},
			getDetail() {
				httpRequest.request("/api/kccl/getKcKcbIndex", 'GET', {
					kc_id: this.kc_id,
				}).then(res => {
					this.dataAll = res.data
				})
			}
		}
	}
</script>

<style>
	.huibox {
		padding: 10rpx 20rpx;
		border-radius: 50rpx;
		color: #999;
		margin: 30rpx 30rpx 0 0;
		background-color: #f7f7f7;
		font-size: 26rpx;
	}
</style>